package com.cskaoyan.config;

import com.cskaoyan.interceptor.HandlerInterceptor1;
import com.cskaoyan.interceptor.HandlerInterceptor4;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author stone
 * @date 2022/11/15 21:00
 */
@EnableWebMvc
@ComponentScan("com.cskaoyan.controller")
public class WebConfiguration implements WebMvcConfigurer {

    @Autowired
    @Qualifier("handlerInterceptor2")
    HandlerInterceptor handlerInterceptor2;
    @Autowired
    @Qualifier("handlerInterceptor3")
    HandlerInterceptor handlerInterceptor3;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new HandlerInterceptor1()).addPathPatterns("/hello/**");
        registry.addInterceptor(handlerInterceptor2);//.addPathPatterns("/**"); 默认的作用范围是/**
        registry.addInterceptor(handlerInterceptor3).addPathPatterns("/goodbye/**");
        registry.addInterceptor(new HandlerInterceptor4());
    }
}
